﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace DevKnightlie.WPF.AutoForm.FieldDefinitions
{
    /// <summary>
    /// Field definition which creates a TextBlock with no field label
    /// </summary>
    public class StaticTextFieldDefinition: BaseFieldDefinition
    {
        #region Methods

        public override void BuildInputControl()
        {
            ContentControl container = new ContentControl()
            {
                IsTabStop = false
            };
            TextBlock textBlock = new TextBlock()
            {
                Text = Title,
                TextWrapping = TextWrapping.Wrap
            };
            if (!String.IsNullOrEmpty(PropertyName))
            {
                Binding textBinding = new Binding(PropertyName);
                BindingOperations.SetBinding(textBlock, TextBlock.TextProperty, textBinding);
            }
            container.Content = textBlock;
            InputControl = null;
            ContainerControl = container;
        }

        public override void BuildLabelControl()
        {
            LabelControl = null;
        }

        #endregion
    }
}
